package com.cn.springcloudwechat.controller.articleAndMenu;


import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.articleAndMenu.YmSubjectPackage;
import com.cn.springcloudwechat.service.articleAndMenu.YmSubjectPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Administrator
 * @create: 2018/7/20 18:29
 */

@RestController
@RequestMapping("/web/subjectPackage/")
public class YmSubjectPackageControllerWeb {
    @Autowired
    YmSubjectPackageService ymSubjectPackageService;

    /**
     * 添加专题包
     *
     * @param ajaxRes
     * @param ymSubjectPackage
     * @param articleIdList
     * @return
     */
    @RequestMapping(value = "insertYmSubjectPackageAndYmSubject", method = RequestMethod.POST)
    public AjaxRes insertYmSubjectPackageAndYmSubject(AjaxRes ajaxRes, YmSubjectPackage ymSubjectPackage, List<Long> articleIdList) {
        ymSubjectPackageService.insertYmSubjectPackageAndYmSubject(ymSubjectPackage, articleIdList);
        ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
        return ajaxRes;
    }

    /**
     * 获取专题包
     *
     * @param ajaxRes
     * @return
     */
    @RequestMapping(value = "getAllYmSubjectPackage", method = RequestMethod.GET)
    public AjaxRes getAllYmSubjectPackage(AjaxRes ajaxRes) {
        List<YmSubjectPackage> ymSubjectPackages = ymSubjectPackageService.getAllYmSubjectPackage();
        ajaxRes.setSucceed(ymSubjectPackages);
        return ajaxRes;
    }

    /**
     * 根据专题包id 获取某个专题包
     *
     * @param ajaxRes
     * @param subjectPackageId
     * @return
     */
    @RequestMapping(value = "getYmSubjectPackageAndArticle", method = RequestMethod.GET)
    public AjaxRes getYmSubjectPackageAndArticle(AjaxRes ajaxRes, Long subjectPackageId) {
        YmSubjectPackage ymSubjectPackage = ymSubjectPackageService.getYmSubjectPackageAndArticle(subjectPackageId);
        ajaxRes.setSucceed(ymSubjectPackage);
        return ajaxRes;
    }

    /**
     * 更新专题包
     *
     * @param ajaxRes
     * @param ymSubjectPackage
     * @param articleIdList
     * @return
     */
    @RequestMapping(value = "updateYmSubjectPackage", method = RequestMethod.POST)
    public AjaxRes updateYmSubjectPackage(AjaxRes ajaxRes, YmSubjectPackage ymSubjectPackage, List<Long> articleIdList) {
        ymSubjectPackageService.updateYmSubjectPackage(ymSubjectPackage, articleIdList);
        ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
        return ajaxRes;
    }


}
